#include "widget.h"
#include "ui_widget.h"
#include <QtQml/QQmlContext>
#include <QtQuick/QQuickView>
#include <QVBoxLayout>
#include <QTimer>

Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);
    m_pWebView = new QQuickWidget();
    m_pWebView->setSource(QUrl(u"qrc:/new/prefix1/Main.qml"_qs));
    m_pWebView->setResizeMode(QQuickWidget::SizeRootObjectToView);
    m_pWebView->rootContext()->setContextProperty("widget", this);
    QVBoxLayout *layout = new QVBoxLayout(ui->wgtWeb);
    layout->addWidget(m_pWebView);
    QTimer::singleShot(2000, this, [this](){
        emit sigGo(QUrl::fromUserInput(ui->lineEdit->text()));
    });
}

Widget::~Widget()
{
    delete ui;
}

void Widget::setText(QString url)
{
    ui->lineEdit->setText(url);
}

void Widget::on_btnBack_clicked()
{
    emit sigBack();
}


void Widget::on_btnRefresh_clicked()
{
    emit sigReflash();
}


void Widget::on_btnForward_clicked()
{
    emit sigForward();
}


void Widget::on_btnGo_clicked()
{
    emit sigGo(QUrl::fromUserInput(ui->lineEdit->text()));
}

